<template>
    <!-- Your template code here -->
    <div class="h-40 py-10 text-lg">
        <div class="text-center text-yd-orange mb-4">
            <span>快来分享你的日常吧</span>
        </div>

        <van-uploader v-model="fileList" multiple :after-read="afterRead" />
    </div>
    <van-cell-group class="mb-4">
        <van-field v-model="imagedesp" rows="2" autosize label="此刻的想法" type="textarea" maxlength="50" placeholder="请输入"
         show-word-limit />
    </van-cell-group>
    <Button class="w-full" size="lg" type="" @click="onsubmit">发布</Button>
    <div></div>
</template>
<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
import 'vant/es/notify/style';
import common from '../api/common';
import { showNotify } from 'vant';
const fileList = ref([]);
const router = useRouter();
let imagedesp = ref('');
const onpublish = (params) => {
    common.publish(params).then((response) => {
        console.log(response, 'response');
        if (response.code == 200) {
            showNotify({ type: 'success', message: `${response.desc}` });
            router.push('/mypicture');
        } else {
            showNotify({ type: 'danger', message: `${response.desc}` });
        }
    });
};
const onsubmit = () => {
    console.log(fileList.value[0].file);
    const formData = new FormData();
    fileList.value.forEach((item) => {
        console.log(item.file);
        formData.append(item.file.name, item.file);
    });
    axios
        .post(' http://120.26.56.51:7001/api/uploadImage', formData)
        // .post(' http://127.0.0.1:7001/api/uploadImage', formData)
        .then((response) => {
            console.log(response);
            onpublish({
                imagedesp: imagedesp.value,
                imageUrl: response.data.imagerul,
            });
        })
        .catch((error) => {
            console.log(error);
        });
};
const afterRead = (file) => {
    // 此时可以自行将文件上传至服务器
    console.log(file);
};
</script>
<style lang="scss">
/* Your style code here */
</style>
